package com.situ.library.service.impl;

import com.situ.library.dao.ITypeDao;
import com.situ.library.dao.impl.TypeDaoImpl;
import com.situ.library.pojo.entity.Type;
import com.situ.library.pojo.query.TypeQuery;
import com.situ.library.service.ITypeService;
import com.situ.library.util.PageInfo;

import java.util.List;

public class TypeServiceImpl implements ITypeService {
    private ITypeDao typeDao = new TypeDaoImpl();

    @Override
    public PageInfo selectByPage(TypeQuery typeQuery) {
        List<Type> list = typeDao.selectByPage(typeQuery);
        //现在要搜索的是符合条件的总的数量
        int totalCount = typeDao.selectTotalCount(typeQuery);

        return  PageInfo.ok(totalCount, list);
    }

    @Override
    public void deleteById(int id) {
        typeDao.deleteById(id);
    }

    @Override
    public void deleteAll(String[] ids) {
        //delete from type where id in(2, 4, 5);
        for (String id : ids) {
            typeDao.deleteById(Integer.parseInt(id));
        }
    }

    @Override
    public void add(Type type) {
        typeDao.add(type);
    }

    @Override
    public void update(Type type) {
        typeDao.update(type);
    }

    @Override
    public Type selectById(int id) {
        return typeDao.selectById(id);
    }

    @Override
    public List<Type> selectAll() {
        return typeDao.selectAll();
    }

}
